<?php
namespace app\shop31\model;

use think\Model;
use \think\facade\Db;

class Goods extends Model
{
    //获取器
    public function getAddtimeAttr($v)
    {
        return date("Y-m-d H:i:s",$v);
    }
    //搜索器
    //模糊搜索
    public function searchNameAttr($q,$v)
    {
        $q->where('a.name','like',"%{$v}%");
    }
    //推荐
    public function searchIsShowAttr($q,$v)
    {
        $q->where('is_show','=',"{$v}");
    }
    //热门
    public function searchIsHotAttr($q,$v)
    {
        $q->where('is_hot','=',"{$v}");
    }
    //下架
    public function searchIsDownAttr($q,$v)
    {
        $q->where('is_down','in',"{$v}");
    }
    //分类
    public function searchCidAttr($q,$v)
    {
        $q->where('cid','=',"{$v}");
    }

    public static function getGoodsList($where,$param)
    {
        $list = Goods::alias('a')
            ->withSearch(array_keys($where),$where)
            ->leftJoin('ecm_category b','a.cid=b.id')
            ->field("a.id,a.name,a.photo_x,a.price,b.name as aname,a.addtime,a.is_show,a.is_down,a.is_hot")
            ->paginate([
                'list_rows'=>3,
                'query' => $param
            ]);

        return $list;
    }
}